@extends('welcome')
<link rel="stylesheet" href="/Home/User/css/safe/ms-style.min.css" />
<link rel="stylesheet" href="/Home/User/css/safe/personal_member.min.css" />
<link rel="stylesheet" href="/Home/User/css/safe/Snaddress.min.css" />
<link rel="stylesheet" href="/Home/login/css/landreg.css" />
<!-- 收藏列表部分样式 -->
<link rel="stylesheet" href="/Home/collect/user.css" />
<link rel="stylesheet" href="/Home/collect/userleft.css" />
<link rel="stylesheet" href="/Home/collect/asyncbox.css" />
<!-- 表格样式 -->
<link rel="stylesheet" href="/Home/address/css.css" />
<link rel="stylesheet" href="/Home/address/sui.css" />
<link rel="stylesheet" href="/Home/address/common.min.css" />
<!--导入地区联动插件-->
<script type="text/javascript" src="/Home/UserEdit/jquery.js"></script>
<script type="text/javascript" src="/Home/UserEdit/area.js"></script>
<script type="text/javascript" src="/Home/UserEdit/location.js"></script>
@section('titletitle','密码修改--优品惠')
@section('zhong_content')
  <br/>
  <!-- 用户中心开始 -->
  <div id="ms-center" class="personal-member">
    <div class="cont">
      <div class="cont-side">
        <div class="side-neck">
          <i></i>
        </div>
        <div class="ms-side">
          <article class="side-menu side-menu-off">
            <dl class="side-menu-tree">
              <dt>订单管理</dt>
              <dd><a  href="{{url('/home/order/xiangqing')}}" target="_self"><span class="active"></span>订单中心</a></dd>
            </dl>
            <dl class="side-menu-tree">
              <dt>账户管理</dt>
              <dd><a href="{{url('home/user/edit')}}" target="_self"><span class="active"></span>我的资料</a></dd>
              <dd><a href="{{url('home/user/password')}}" target="_self" style="color:#f70"><span class="active"></span>密码修改</a></dd>
              <dd><a href="{{url('home/user/address')}}" target="_self"><span></span>地址管理</a></dd>
            </dl>
            <dl class="side-menu-tree">
              <dt>收藏管理</dt>
              <dd><a href="{{url('home/collect/index')}}" target="_self"><span class="active"></span>收藏列表</a></dd>
            </dl>
            <a ison="on" class="switch-side-menu icon-up-side"><i></i></a>
          </article>
        </div>
      </div>
      <div class="cont-main">
        <div class="main-wrap mt15">
        @if (count($errors) > 0)
          <div class="">
            <ul>
              @foreach ($errors->all() as $error)
                <div class="cont-main alert alert-danger alert-dismissable" style="width:400px">
                  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                  <li>{{ $error }}</li>
                </div>
              @endforeach
            </ul>
          </div>
        @endif
        @if(session('success'))
        <div class="cont-main alert alert-success alert-dismissable" style="width:400px">
            <h5> {{session('success')}} </h5>
        </div>
        @endif
        @if(session('error'))
        <div class="cont-main alert alert-danger alert-dismissable" style="width:400px">
           <h5> {{session('error')}} </h5>
        </div>
        @endif
          <!-- 密码修改列表 start -->
          <h3><strong>修改密码</strong></h3>
          <div class="form-list tab-switch personal-wrap-show">
            <form id="passform" action="{{url('/home/user/passupdate')}}" method="post" enctype="multipart/form-data">
              <div class="control-group clearfix">
                <label class="control-label"><em>*&nbsp;</em>原始密码：</label>
                <div class="controls">
                  <input class="text" name="oldpass" style="width:280px" type="password">
                </div>
                <div id="oldpass" style="background-color:#FFF3F3;color:#EB0007;border:1px solid #FFADB0;padding-left:9px;margin-left:480px;width:250px;height:26px;line-height:26px;display:none">请输入原始密码</div>
              </div>
              <div class="control-group clearfix">
                <label class="control-label"><em>*&nbsp;</em>新密码：</label>
                <div class="controls">
                  <input class="text" name="newpass" style="width:280px" type="password">
                </div>
                <div id="newpass" style="height:26px;line-height:26px;padding-left:9px;margin-left:480px;width:300px">6-18位字符，可使用字母、数字或符号的组合</div>
              </div>
              <div class="control-group clearfix">
                <label class="control-label"><em>*&nbsp;</em>确认新密码：</label>
                <div class="controls lh26">
                  <input class="text" name="renewpass" style="width:280px" type="password">
                </div>
                <div id="renewpass" style="background-color:#FFF3F3;color:#EB0007;border:1px solid #FFADB0;padding-left:9px;margin-left:480px;width:250px;height:26px;line-height:26px;display:none">两次输入的密码不一致</div>
              </div>
              <div class="control-group clearfix priority-low">
                <label class="control-label">&nbsp;</label>
                <div style="float:left;">
                  <button type="submit" class="ms-stand-btn1" style="width:100px">确认修改</button>
                </div>
                <div id="" class="error-place"></div>
                <div class="error-place mt29"></div>
              </div>
              {{csrf_field()}}
            </form>
          </div>
          <!-- 密码修改列表 end -->
        </div>
      </div>
    </div>
  </div>
  <!-- 用户中心结束 -->
@endsection
@section('myjs')
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
    //全局变量 标识
    var OLDPASS = false;
    var NEWPASS = false;
    var REPASS = false;

    //绑定表单提交事件
    $('#passform').submit(function(){
      //触发所有的丧失焦点事件
      $('#passform').find('input').trigger('blur');
      //判断所有的字段都检测成功后提交
      if(OLDPASS && NEWPASS && REPASS){
          //都成功
          return true;
      }
      //阻止默认行为
      return false;
    })

    //给原密码绑定丧失焦点事件
    $('input[name=oldpass]').blur(function(){
      var oldpass = $(this).val();
      var dd = $(this);
      if(oldpass == ''){
        $('#oldpass').css('display','block');
        $('#oldpass').html('原始密码不能为空');
        OLDPASS = false;
        return false;
      }else{
        //发送ajax
        $.post('/home/user/passtest',{oldpass:oldpass},function(data){
          if(data == 1){
            //密码一致
            $('#oldpass').css('display','block');
            $('#oldpass').css('color','green');
            $('#oldpass').css('border','');
            $('#oldpass').css('background-color','');
            $('#oldpass').html('ok');
            OLDPASS = true;
          }else{
            //密码不一致
            $('#oldpass').css('display','block');
            $('#newpass').css('color','red');
            $('#newpass').css('border','1px solid #FFADB0');
            $('#newpass').css('background-color','#FFF3F3');
            $('#oldpass').html('原始密码不正确,请重新输入');
            OLDPASS = false;
          }
        })
      }
    });

    //给新密码绑定丧失焦点事件
    $('input[name=newpass]').blur(function(){
      //获取用户输入的密码
      var newpass = $(this).val();
      //声明正则
      var reg = /^\w{6,18}$/;
      if(reg.test(newpass)){
        //正确
        $('#newpass').css('color','green');
        $('#newpass').css('border','');
        $('#newpass').css('background-color','');
        $('#newpass').html('ok');
        NEWPASS = true;
      }else{
        //错误
        $('#newpass').css('color','red');
        $('#newpass').css('border','1px solid #FFADB0');
        $('#newpass').css('background-color','#FFF3F3');
        $('#newpass').html('密码为空或格式不正确');
        NEWPASS = false;
      }
    });

    //给确认密码绑定丧失焦点事件
    $('input[name=renewpass]').blur(function(){
      //获取用户输入的确认密码
      var renewpass = $(this).val();
      //获取密码
      var newpass = $('input[name=newpass]').val();
      // alert(renewpass);
      // alert(newpass);
      if(renewpass == ''){
        //错误
        $('#renewpass').css('display','block');
        $('#renewpass').css('color','red');
        $('#renewpass').css('border','1px solid #FFADB0');
        $('#renewpass').css('background-color','#FFF3F3');
        $('#renewpass').html('确认密码不能为空');
        REPASS = false;
        return false;
      }

      if(renewpass == newpass){
        //正确
        $('#renewpass').css('display','block');
        $('#renewpass').css('color','green');
        $('#renewpass').css('border','');
        $('#renewpass').css('background-color','');
        $('#renewpass').html('ok');
        REPASS = true;
      }else{
        //错误
        $('#renewpass').css('display','block');
        $('#renewpass').css('color','red');
        $('#renewpass').css('border','1px solid #FFADB0');
        $('#renewpass').css('background-color','#FFF3F3');
        $('#renewpass').html('两次输入的密码不一致,请确认后重新输入');
        REPASS = false;
        return false;
      }
    })

    //单独删除收藏的商品
    $('.pic_del').click(function(){
      var id = $(this).parents('dd').find('.pic_delete').html();
      // alert(id);
      var dd = $(this);
      //发送ajax
      $.post('/home/collect/delete',{id:id},function(data){
        if(data == 1){
          dd.parents('dd').remove();
          alert('删除成功');
        }else{
          alert('删除失败');
        }
      })
      return false;
    });

    //选择和取消选择全部商品
    var inp = document.getElementsByName('chk_list');
    var chk = document.getElementById('chk_all');
    $('#chk_all').click(function(){
      for (var i = 0; i <  inp.length; i++) {
         inp[i].checked = chk.checked;
      };
    })

    //删除全部商品
    $('#del_all').click(function(){
      var chk = document.getElementById('chk_all');
      // alert(chk.checked);//选中为true,未选中为false
      //如果没有选中
      if(chk.checked == false){
        alert('请选择要删除的商品');
      }else{
        //发送ajax
        $.post('/home/collect/deleteall',function(data){
          if(data == 1){
            $('.skim_list').empty();
            alert('删除成功');
          }else{
            alert('删除失败');
          }
        })
      }
      return false;
    });
</script>
@show